package com.study.practice.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 创建一个观众切面
 */
@Aspect
@Component
public class Audience {

    @Pointcut("execution(* com.study.practice.controller.TestStrReplace.*(..))")
    public void performance(){}

    @Before("performance()")
    public void silenceCellPhone() {
        System.out.println("silence cell phone");
    }

    @Before("performance()")
    public void takeSeats() {
        System.out.println("taking seats");
    }

    @AfterReturning("performance()")
    public void successReturn() {
        System.out.println("clap clap clap");
    }

    @AfterThrowing("performance()")
    public void exception() {
        System.out.println("demanding a refund");
    }

    @Around("performance()")
    public void watchPerformance(ProceedingJoinPoint jp) {
        System.out.println("Around before****");
        try {
            jp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("Around after******");
    }

}
